<template>
  <div class="navi-bar">
    <div class="navi-bar-box">
      <div class="top">
        <div class="user-head-image">
          <head-image
            :name="userStore.userInfo.nickName"
            :size="38"
            :url="userStore.userInfo.headImageThumb"
            @click.native="showSettingDialog = true"
          >
          </head-image>
        </div>
        <div class="menu">
          <router-link class="link" v-bind:to="'/home/chat'">
            <div class="menu-item">
              <span class="icon iconfont icon-chat"></span>
              <div v-show="unreadCount > 0" class="unread-text">
                {{ unreadCount }}
              </div>
            </div>
          </router-link>
          <router-link class="link" v-bind:to="'/home/friend'">
            <div class="menu-item">
              <span class="icon iconfont icon-friend"></span>
            </div>
          </router-link>
          <router-link class="link" v-bind:to="'/home/group'">
            <div class="menu-item">
              <span
                class="icon iconfont icon-group"
                style="font-size: 28px"
              ></span>
            </div>
          </router-link>
        </div>
      </div>

      <div class="botoom">
        <div class="bottom-item" @click="setFullscreenStatus">
          <el-icon><FullScreen /></el-icon>
        </div>
        <div class="bottom-item" @click="showSetting">
          <span
            class="icon iconfont icon-setting"
            style="font-size: 20px"
          ></span>
        </div>
        <div class="bottom-item" @click="onExit()" title="退出">
          <span class="icon iconfont icon-exit"></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { FullScreen } from "@element-plus/icons-vue";
const userStore: any = { userInfo: {} }; //TODO
const chatStore: any = { chats: [] }; //TODO
const showSettingDialog = ref(false);
const emits = defineEmits(["setFullscreenStatus", "showSetting", "onExit"]);
const unreadCount = computed(() => {
  let unreadCount = 0;
  let chats = chatStore.chats;
  chats.forEach((chat: any) => {
    if (!chat.delete) {
      unreadCount += chat.unreadCount;
    }
  });
  return unreadCount;
});
function setFullscreenStatus() {
  emits("setFullscreenStatus");
}
function showSetting() {
  emits("showSetting");
}
function onExit() {
  emits("onExit");
}
</script>

<style scoped lang="scss">
.navi-bar {
  outline: none !important;
  user-select: none;
  --icon-font-size: 22px;
  --width: 60px;
  width: var(--width);
  background: var(--im-color-primary-light-1);
  padding-top: 20px;
  .navi-bar-box {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .botoom {
      margin-bottom: 30px;
    }
  }

  .user-head-image {
    display: flex;
    justify-content: center;
  }

  .menu {
    height: 200px;
    //margin-top: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-content: center;

    .link {
      text-decoration: none;
    }

    .router-link-active .menu-item {
      color: #fff;
      background: var(--im-color-primary-light-2);
    }

    .link:not(.router-link-active) .menu-item:hover {
      color: var(--im-color-primary-light-7);
    }

    .menu-item {
      position: relative;
      color: var(--im-color-primary-light-4);
      width: var(--width);
      height: 46px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 12px;

      .icon {
        font-size: var(--icon-font-size);
      }

      .unread-text {
        position: absolute;
        background-color: var(--im-color-danger);
        left: 28px;
        top: 8px;
        color: white;
        border-radius: 30px;
        padding: 0 5px;
        font-size: var(--im-font-size-smaller);
        text-align: center;
        white-space: nowrap;
        border: 1px solid #f1e5e5;
      }
    }
  }

  .bottom-item {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 50px;
    width: 100%;
    cursor: pointer;
    color: var(--im-color-primary-light-4);
    font-size: var(--icon-font-size);

    .icon {
      font-size: var(--icon-font-size);
    }

    &:hover {
      font-weight: 600;
      color: var(--im-color-primary-light-7);
    }
  }
}
</style>
